{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "0f77c456-02cf-4c44-b6fa-c4b120e6f669",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "fc9040e7-a59d-4fd4-9f9e-f68cedf9d306",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[10 20 30 40 60 50 70 80 90]\n"
     ]
    }
   ],
   "source": [
    "n=np.array([10,20,30,40,60,50,70,80,90])\n",
    "print(n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "7c503c9c-5e1d-4c6a-9fd4-b5ebf869b8c7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[10 20 30]\n"
     ]
    }
   ],
   "source": [
    "print(n[:3]) # 省略起始位置，那么默认从0开始[0,3),步长为1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "514b64d5-96cd-4f7c-bd85-c6d3b429a399",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[40 60 50]\n"
     ]
    }
   ],
   "source": [
    "print(n[3:6])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "5a064a5b-2356-440a-8a77-e6b1315afeea",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[70 80 90]\n"
     ]
    }
   ],
   "source": [
    "print(n[6:])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "4c5a1e54-40da-4817-bbbb-2b4619cb0f80",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[70 80]\n"
     ]
    }
   ],
   "source": [
    "print(n[6:8])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "8d275bc4-8b68-4bfa-88e9-e414863d7684",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[10 20 30 40 60 50 70 80 90]\n"
     ]
    }
   ],
   "source": [
    "print(n[::]) # 获取数组中的所有元素"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "4429f250-3fa3-41d2-b500-bda864567c06",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[10 30 60 70 90]\n"
     ]
    }
   ],
   "source": [
    "# 修改步长\n",
    "print(n[0::2])  # 获取索引为0，步长为2的值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "f6ee1750-02ed-4b1b-aedb-a654ba9ca363",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[20 70]\n"
     ]
    }
   ],
   "source": [
    "print(n[1::5])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "bd182d07-7ec6-4045-96b3-0b9cb8093d49",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[90 80 70 50 60 40 30 20 10]\n"
     ]
    }
   ],
   "source": [
    "# 步长还可以是负数\n",
    "print(n[::-1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "17082a8a-1180-401a-92a0-4e0026194937",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[90 70 60 30]\n"
     ]
    }
   ],
   "source": [
    "print(n[-1:-9:-2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "725cfff1-4f22-401c-a311-4424985a6654",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[10 20 30 40 50 60]\n"
     ]
    }
   ],
   "source": [
    "# 列表切片操作与数组的切片操作的区别\n",
    "array=np.array([10,20,30,40,50,60])\n",
    "print(array)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "07152e55-7667-4565-a99e-02b21c21b588",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[20 30 40]\n",
      "[30 40]\n",
      "[100  40]\n",
      "[ 20 100  40]\n"
     ]
    }
   ],
   "source": [
    "arr=array[1:4]\n",
    "print(arr)\n",
    "arr1=arr[1:4]\n",
    "print(arr1)\n",
    "arr1[0]=100\n",
    "print(arr1)\n",
    "print(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "d0259da9-c525-41c1-974a-35448b20241b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2, 3, 4]\n",
      "[1, 2, 3, 4, 5]\n"
     ]
    }
   ],
   "source": [
    "lst=[1,2,3,4,5]\n",
    "lst1=lst[1:4]\n",
    "print(lst1)\n",
    "print(lst)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "ea6fe845-be2f-4df1-97f0-fd7f826b7b33",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 1  2  3]\n",
      " [ 5  6  7]\n",
      " [ 8  9 10]]\n"
     ]
    }
   ],
   "source": [
    "# 二维数组的切片操作\n",
    "arr=np.array([[1,2,3],[5,6,7],[8,9,10]])\n",
    "print(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "0af3ba0c-2bab-4f5c-823f-a93ed602cb98",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7\n"
     ]
    }
   ],
   "source": [
    "print(arr[1,2])  # 索引为1的行，索引为2的列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "582f1e39-49d0-481f-a7e4-9d49f77da854",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[2 3]\n",
      " [6 7]]\n"
     ]
    }
   ],
   "source": [
    "print(arr[:2, 1:])  # 从索引为0的行到索引为2的行，不包含2，从索引为1的列开始，一直到最后的列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "774e9de7-41a2-47ca-8dd7-688c5dffc566",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[5 6]\n"
     ]
    }
   ],
   "source": [
    "print(arr[1, :2]) # 逗号之前表示行，到索引为2的列结束，不包含2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "1c395aba-f68a-41c3-9dca-dcae0a0422d6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[3 7]\n"
     ]
    }
   ],
   "source": [
    "print(arr[:2, 2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "c7c0f2af-8c55-45a7-b3de-df12b0917886",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[5 6 7]\n"
     ]
    }
   ],
   "source": [
    "print(arr[1, :])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cad67e39-2fdc-4fa3-9717-9fc8d770db18",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7711708b-78cc-4037-a758-79a63823fc6b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "42040d33-5e6b-40f4-a836-935833da548b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b3a7e99f-fb27-427e-ac71-12b24183de25",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a57b9a73-fa5f-4cc7-8947-452cd44daf81",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d26b3a16-ddb3-4157-b416-96ca8e229745",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "261a919f-6c15-412e-b04e-6e0997a212df",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9ea1974d-f4b7-4e75-baf0-fc0e19304899",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
